package com.neusoft.a312cxy.android18cxy.model;

import com.neusoft.a312cxy.android18cxy.Interface.ClubFace;
import com.neusoft.a312cxy.android18cxy.Listener.ClubListListener;
import com.neusoft.a312cxy.android18cxy.Listener.OrderListener;
import com.neusoft.a312cxy.android18cxy.bean.ClubListBean;
import com.neusoft.a312cxy.android18cxy.service.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Young on 2017/9/30.
 */

public class ClubModel implements ClubFace {

    private Retrofit retrofit;
    private ClubService ClubService;
    private static final String BASE_URL = "http://172.24.10.175/workout/api.php/";//主机地址

    public ClubModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getList(String SessionId, int page,final ClubListListener listListener) {
        ClubService = retrofit.create(ClubService.class);
        Call<List<ClubListBean>> call =ClubService.getClubList(SessionId,page);
        call.enqueue(new Callback<List<ClubListBean>>() {
            @Override
            public void onResponse(Call<List<ClubListBean>> call, Response<List<ClubListBean>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else {
                    listListener.onFail("onresponse fail");
                }
            }

            @Override
            public void onFailure(Call<List<ClubListBean>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }

    public Call getClubInfo(int id)
    {
        ClubService ClubService=retrofit.create(ClubService.class);
        return ClubService.getClubInfo(id);
    }

    public Call getClubCourse(int id)
    {
        ClubService ClubService=retrofit.create(ClubService.class);
        return ClubService.getClubInfoList(1,id);
    }

    public  Call guanzhu(String userid ,String fan_id, String fans_type)
    {
        ClubService foodService=retrofit.create(ClubService.class);
        return  foodService.guanzhu(userid,fan_id,fans_type);
    }
    public Call IsCollection(String fan_id ,String userid , String fans_type)
    {
        ClubService clubService=retrofit.create(ClubService.class);
        return clubService.IsCollection(fan_id,userid,fans_type);
    }

    //订单
    @Override
    public void signcourse(String participantname,String course_id,String participanttel,String adultnum,String paytype,
                          String pay,String paynotice,int userid,final OrderListener listener) {
        ClubService = retrofit.create(ClubService.class);
        Call<String> call= ClubService.signcourse(participantname,course_id,participanttel,adultnum,paytype,pay,paynotice,userid);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else {
                    listener.onFail("onresponse fail");
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }


}